<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="充值类型"
          hasFeedback >

   <a-select
	  v-model="recoilType"
      style="width: 200px"
      @focus="focus"
      ref="select"
      @change="handleChange"
    >
      <a-select-option value="2">
        对公转账
      </a-select-option>
      <a-select-option value="3">
        现金充值
      </a-select-option>
      <a-select-option value="4">
        消费返充
      </a-select-option>
	  <a-select-option value="5">
	    活动充值
	  </a-select-option>
	  <a-select-option value="6">
	    售后返充
	  </a-select-option>
    </a-select>
          <!-- <a-input placeholder="请选择充值类型" v-decorator="['recoilType', {}]" /> -->
           <!-- <a-input placeholder="请输入充值账号" v-model="this.model.userName" disabled="disabled"/> -->
           <!-- // v-show="xianshi" -->
        </a-form-item>
    

  <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="充值金额"
          hasFeedback >
          <a-input type="number" placeholder="请输入充值金额" v-decorator="['recoilMoney', {}]" />
       
           <!-- // v-show="xianshi" -->
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="加工厂责任"
          hasFeedback
		   v-if="recoilType==6">
          <a-input type="number" placeholder="请填写责任金额" v-decorator="['factoryResponsibility', {}]" />
        </a-form-item>

          <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="平台责任"
          hasFeedback  
		  v-if="recoilType==6">
          <a-input type="number" placeholder="请填写责任金额" v-decorator="['platformResponsibility', {}]" />
        </a-form-item>

          <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注"
          hasFeedback >
          <a-input placeholder="请输入备注" v-decorator="['remark', {}]" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
import { deleteAction, getAction, putAction, postAction, downFile, getFileAccessHttpUrl } from '@/api/manage'
  export default {
    name: "xitongfanchong",
    data () {
      return {
        recoilType:'',  //反冲类型
        userId:'',
        recoilMoney:'',//反冲金额
        factoryResponsibility:'',//工厂责任
        platformResponsibility:'',//平台责任
        remark:'', //备注
        title:"操作",
        visible: false,
        xianshi:false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/Finance/Systemrecoil",
          edit: "/Finance/Systemrecoil",
        },
      }
    },
    created () {
      
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
      
        this.userId=record;
        this.form.resetFields();
        this.model[0] = Object.assign({}, record);
         // this.model = record;
          console.log("转化了?"+this.model[0]);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model[0],'userId'))
	  
        });
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }

         
            let formData = Object.assign(this.model, values);
              formData['userId']=this.userId;
              formData['recoilType']=this.recoilType;
	          
            getAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('aaa');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style scoped>

</style>